<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><a href="javascript:void(0);" onclick="memberlistReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span
                    class="l-btn-text">重载</span></span></a></td>
            <td><span style="line-height:30px;">注册日期</span>
                <input id="memberlistStartOn" style="width:152px" type="text" class="easyui-datetimebox"> </input>至
                <input id="memberlistEndOn" style="width:152px" type="text" class="easyui-datetimebox"> </input>
            </td>
            <td>
                <select id="memberlistKeywordsType" class="forminput inputstyle textbox-text validatebox-text" style="width:80px">
                    <option value="id">会员ID</option>
                    <option value="nickname">会员昵称</option>
                    <option value="phone">手机号</option>
                </select></td>
            <td><input id="memberlistKeywords" style="width:120px" type="text"
                                class="easyui-input textbox"></td>
            <td>
                <select id="memberlistStatus" class="forminput inputstyle textbox-text validatebox-text" style="width:110px" onchange="memberlistSearch()">
                    <option value="">--全部状态--</option>
                    <option value="normal">正常</option>
                    <option value="frozen">冻结</option>
                    <option value="lock">锁定</option>
                    <option value="deleted">已删除</option>
                </select></td>
            <td><a href="javascript:void(0);" onclick="memberlistSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span
                    class="l-btn-text">查询</span></span></a></td>
            <td><a href="javascript:void(0);" onclick="memberlistReset();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxinrefresh39"></i><span
                    class="l-btn-text">重置</span></span></a></td>
            <td><a href="javascript:void(0);" onclick="shopmemberExport();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-xiazai"></i><span
                    class="l-btn-text">导出会员</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con"  style="-moz-user-select:none;">
    <table id="memberlist"></table>
</div>
<div id="memberlistdlg" class="easyui-dialog" style="width:840px; height:520px;" title="信息框" closed="true"></div>
<div id="memberlistteamdlg" class="easyui-dialog" style="width:940px; height:560px;" title="信息框" closed="true"></div>
<script>
    var enable_restore = "<?php echo $enable_restore;?>";
    var memberlistReload = function () {
        $("#memberlist").datagrid('reload');
    };
    var shopmemberExport = function () {
        showLoading('.con');
        $.post('/admin/member/shopmemberexport', {
            keywordsType: $('#memberlistKeywordsType').val(),
            keywords: $('#memberlistKeywords').val(),
            start_on: $('#memberlistStartOn').val(),
            end_on: $('#memberlistEndOn').val(),
            status: $('#memberlistStatus').val(),
        }, function (data) {
            hideLoading();
            if (parseInt(data.ret) === 0) {
                $.messager.show({
                    title: '提示',
                    msg: data.msg,
                    timeout: 3000,
                    showType: 'slide'
                });
                eventmaterialDownload(data.data);
            } else {
                $.messager.alert('提示', data.msg, 'warning');
            }
        }, 'json').fail((response)=> {
            hideLoading();
            $.messager.alert('提示', response.responseText, 'warning');
        });
    };
    var memberlistReset = function (){
        $('#memberlistKeywords').val('');
        $('#tb<?php echo $uniqid;?> #memberlistStartOn').datetimebox('setValue', '');
        $('#tb<?php echo $uniqid;?> #memberlistEndOn').datetimebox('setValue', '');
        memberlistSearch();
    };
    var memberlistSearch = function () {
        var height = $(window).height() - $(".top").height() - 46;
        var width = $(window).width() - $(".leftmenu").width() - 8;
        $("#memberlist").datagrid({
            title: '会员列表',
            width: width,
            height: height,//高度
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: false,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 10,
            pageList: [10, 15, 20, 25],
            method: 'post',
            sortName: 'id',
            sortOrder: 'desc',
            idField: 'id',
            url: '/admin/member/member',
            queryParams: {
                keywordsType: $('#memberlistKeywordsType').val(),
                keywords: $('#memberlistKeywords').val(),
                start_on: $('#memberlistStartOn').val(),
                end_on: $('#memberlistEndOn').val(),
                status: $('#memberlistStatus').val(),
            },
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: false,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            columns: [[
                {field: 'id', title: 'ID', width: '7%'},
                {
                    field: 'avatar', title: '头像', width: '5%', formatter: function (value, rowData, rowIndex) {
                        return value ? "<img height='50px' src='" + value + "'>" : '';
                    }
                },
                {field: 'nickname', title: '用户', width: '25%', formatter: function (value, rowData, rowIndex) {
                        return value + (rowData.deleted_at ? '<span style="color: red">(已删除)</span>' : '');
                    }},
                {
                    field: 'status', title: '状态', align:'center', width: '15%', formatter: function (value, rowData, rowIndex) {
                        if(rowData.deleted_at){
                            return '<span style="color:red">已删除</span>';
                        }else {
                            switch (value) {
                                case 'normal':
                                    return '正常';
                                case 'frozen':
                                    return '冻结';
                                case 'lock':
                                    return '锁定';
                            }
                        }
                    }
                },
                {field: 'login_times', title: '登陆次数', width: '11%', sortable: true},
                {field: 'logined_at', title: '最近登陆时间', width: '15%', sortable: true},
                {field: 'created_at', title: '加入时间', width: '15%', sortable: true},
            ]],
        });
    };
    onDatagridResize("#memberlist");
    memberlistSearch();
</script>
